package com.ruoyi.school.service.impl;

import com.ruoyi.school.domain.Student;
import com.ruoyi.school.domain.dto.HonorWallTopThreeDTO;
import com.ruoyi.school.domain.vo.HonorWallTopThreeVo;
import com.ruoyi.school.handler.wall.WallStrategy;
import com.ruoyi.school.handler.wall.WallStrategyFactory;
import com.ruoyi.school.handler.wall.WallTopThree;
import com.ruoyi.school.mapper.StudentMapper;
import com.ruoyi.school.service.PacHonorWallService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static com.ruoyi.common.utils.PageUtils.startPage;

@Service
public class PacHonorWallServiceImpl implements PacHonorWallService {
    @Resource
    private WallStrategyFactory wallStrategyFactory;

    @Resource
    private StudentMapper studentMapper;
    /**
     * 荣誉墙前三
     *
     * @param honorWallTopThreeDTO
     * @return
     */
    @Override
    public List<HonorWallTopThreeVo> getTopThree(HonorWallTopThreeDTO honorWallTopThreeDTO) {
        if(Objects.isNull(honorWallTopThreeDTO.getWallType())){
            throw new RuntimeException("荣誉类型不存在");
        }
        WallStrategy strategy = wallStrategyFactory.getStrategy(honorWallTopThreeDTO.getWallType());
        WallTopThree wallTopThree = WallTopThree.builder()
                .startTime(honorWallTopThreeDTO.getStartTime())
                .endTime(honorWallTopThreeDTO.getEndTime())
                .wallType(honorWallTopThreeDTO.getWallType())
                .fileType(honorWallTopThreeDTO.getFileType())
                .stuName(honorWallTopThreeDTO.getStuName())
                .stuId(honorWallTopThreeDTO.getStuId())
                .competitionType(honorWallTopThreeDTO.getCompetitionType())
                .certType(honorWallTopThreeDTO.getCertType()).build();

        List<HonorWallTopThreeVo> topThree = strategy.getTopThree(wallTopThree);


        return topThree;
    }

    /**
     * 荣誉列表
     *
     * @param student
     * @return
     */
    @Override
    public List<Student> list(Student student) {
        startPage();
        List<Student> students = studentMapper.getHonorList(student);

        return students;
    }

    /**
     * 获取某个学生的荣誉列表
     *
     * @param honorWallTopThreeDTO
     * @return
     */
    @Override
    public List<HonorWallTopThreeVo> stuHonorList(HonorWallTopThreeDTO honorWallTopThreeDTO) {
        if(Objects.isNull(honorWallTopThreeDTO.getWallType())){
            throw new RuntimeException("荣誉类型不存在");
        }

        WallStrategy strategy = wallStrategyFactory.getStrategy(honorWallTopThreeDTO.getWallType());
        WallTopThree wallTopThree = WallTopThree.builder()
                .wallType(honorWallTopThreeDTO.getWallType())
                .fileType(honorWallTopThreeDTO.getFileType())
                .stuId(honorWallTopThreeDTO.getStuId()).build();

        List<HonorWallTopThreeVo> voList = strategy.getStuHonorList(wallTopThree);
        return voList;
    }

    @Override
    public List<HonorWallTopThreeVo> list2(Student student) {
        startPage();
        List<HonorWallTopThreeVo> students = studentMapper.getHonorList2(student);
        return students;
    }
}
